package com.jy.it.ui.admin;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.jy.it.entity.Admin;
import com.jy.it.service.AdminService;
import com.jy.it.service.impl.AdminServiceImpl;

@Controller
public class AdminController {
	@Autowired
	private AdminService service=null;
	
    @RequestMapping(value="/admin/login",method=RequestMethod.GET)
	public String login() {
		return "admin/admin_login";
	}
    @RequestMapping(value="/admin/login",method=RequestMethod.POST)
    public String login(String username,String password,HttpSession session,Model m) {
    	Admin admin=service.login(username,password);
    	if(admin!=null) {
    		session.setAttribute("admin", admin);//登录成功，记起来后续要用
    		//return "redirect:/wz/add";//跳转到录入违章记录的页面
    		return "redirect:/admin/nav";//跳转到录入违章记录的页面
    	}
    	//如果登录不成功，返回页面提示错误
    	m.addAttribute("err","用户名或密码错误");
    	return "admin/admin_login";
    }
}




